package com.lccviolet;

import java.lang.ref.WeakReference;

/**
 * @author LiChaochao
 * @Date 2021/9/22 20:50
 * @Description 弱引用：不管内存够不够，弱引用都会回收
 */
public class WeakReferenceDemo {

    public static void main(String[] args) {
        Object o1 = new Object();
        WeakReference<Object> o2 = new WeakReference<>(o1);

        System.out.println("o1 = " + o1);
        System.out.println("o2 = " + o2.get());

        o1 = null;
        System.gc();

        System.out.println("o1 = " + o1);
        System.out.println("o2 = " + o2.get());
    }
}
